<?php
namespace Commnet\Model;
use PhalApi\Model\DataModel;

class CommnetCategory extends DataModel {

    protected function getTableName($id) {
        return 'commnet_category';
    }

    //查询分类
    public function checkName($name){
        return $this->getORM()->select('*')->where('name = ?', $name)->fetchOne();
    }

    //新增分类
    public function addCategory( $name ) {
        $info = $this->checkName($name);
        if ( $info ){
            $this->getORM()->where('id',$info['id'])->update( array('count' => $info['count'] +1 ) );
        }else{
            $info = $this->getORM()->insert( array(
                'name' => $name,
                'create_time' => date("Y-m-d H:i:s",time()),
            ));
        }
        return $info;
    }





}
